var addEvent = (function () {
	if (document.addEventListener) {
		return function (el, type, fn) {
			if (el && el.nodeName || el === window) {
				el.addEventListener(type, fn, false);
			} else if (el && el.length) {
				for (var i = 0; i < el.length; i++) {
					addEvent(el[i], type, fn);
				}
			}
		};
	} else {
	return function (el, type, fn) {
		if (el && el.nodeName || el === window) {
			el.attachEvent('on' + type, function () { return 
			fn.call(el, window.event); });

		} else if (el && el.length) {
			for (var i = 0; i < el.length; i++) {
				addEvent(el[i], type, fn);
			}
		}
	};
	}
})();

function getStorage(type) {
	var storage = window[type + 'Storage'],
	delta = 0,
	li = document.createElement('li');
	if (!window[type + 'Storage']) return;
	if (storage.getItem('value')) {
		delta = ((new Date()).getTime() - (new Date()).
		setTime(storage.getItem('timestamp'))) / 1000;
		li.innerHTML = type + 'Storage: ' + storage.getItem('value') + 
		' (last updated: ' + delta + 's ago)';
	} else {
		li.innerHTML = type + 'Storage is empty';
	}
	document.querySelector('#previous').appendChild(li);
}
getStorage('local');

addEvent(document.querySelector('#local'), 'keyup', function () {
	localStorage.setItem('value', this.value);
	localStorage.setItem('timestamp', (new Date()).getTime());
});